/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DataWanderMainPanel.java
 *
 * Created on 2010-03-11, 23:51:06
 */

package com.googlecode.datawander.View;

import com.googlecode.datawander.Presenter.ConnectionValuesException;
import com.googlecode.datawander.Presenter.DataWanderPresenterInt;
import com.googlecode.datawander.i18n.I18n;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Marcin Stachniuk
 */
public class DataWanderMainPanel extends javax.swing.JPanel {

    private DataWanderPresenterInt dataWanderPresenter;

    /** Creates new form DataWanderMainPanel */
    public DataWanderMainPanel() {
        initComponents();
    }

    public void setDataWanderControler(DataWanderPresenterInt dataWanderPresenter) {
        this.dataWanderPresenter = dataWanderPresenter;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jFileChooserDb4oFilename = new javax.swing.JFileChooser();
        jFileChooserDb4oCodeFolder = new javax.swing.JFileChooser();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaLog = new javax.swing.JTextArea();
        jLabelLog = new javax.swing.JLabel();
        jPanelRelationalDatabases = new javax.swing.JPanel();
        jLabelRelationalDatabase = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabelUsername = new javax.swing.JLabel();
        jLabelURL = new javax.swing.JLabel();
        jLabelPassword = new javax.swing.JLabel();
        jTextFieldRelationalUrl = new javax.swing.JTextField();
        jTextFieldRelationalUsername = new javax.swing.JTextField();
        jTextFieldRelationalPassword = new javax.swing.JTextField();
        jPanelMigrations = new javax.swing.JPanel();
        jButtonRelationalToObjectMigration = new javax.swing.JButton();
        jButtonObjectToRelationalMigration = new javax.swing.JButton();
        jLabelMigrations = new javax.swing.JLabel();
        jPanelObjectDatabases = new javax.swing.JPanel();
        jPanelORMappingInfo = new javax.swing.JPanel();
        jLabelJarFile = new javax.swing.JLabel();
        jButtonJarBrowse = new javax.swing.JButton();
        jTextFieldObjectCompiledFolder = new javax.swing.JTextField();
        jLabelObjectedBatabase = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jLabelLocal = new javax.swing.JLabel();
        jLabelFile = new javax.swing.JLabel();
        jTextFieldObjectDatabaseFilename = new javax.swing.JTextField();
        jButtonBrowse = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();

        setLayout(new java.awt.GridBagLayout());

        jTextAreaLog.setColumns(20);
        jTextAreaLog.setRows(5);
        jScrollPane1.setViewportView(jTextAreaLog);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.weighty = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        add(jScrollPane1, gridBagConstraints);

        jLabelLog.setText(I18n.getString("log"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        add(jLabelLog, gridBagConstraints);

        jPanelRelationalDatabases.setLayout(new java.awt.GridBagLayout());

        jLabelRelationalDatabase.setText(I18n.getString("relationaldatabase"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 0);
        jPanelRelationalDatabases.add(jLabelRelationalDatabase, gridBagConstraints);

        jSeparator1.setName(""); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipady = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
        jPanelRelationalDatabases.add(jSeparator1, gridBagConstraints);

        jLabelUsername.setText(I18n.getString("username"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 0, 0);
        jPanelRelationalDatabases.add(jLabelUsername, gridBagConstraints);

        jLabelURL.setText(I18n.getString("url"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 0, 0);
        jPanelRelationalDatabases.add(jLabelURL, gridBagConstraints);

        jLabelPassword.setText(I18n.getString("password"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 0, 0);
        jPanelRelationalDatabases.add(jLabelPassword, gridBagConstraints);

        jTextFieldRelationalUrl.setText("jdbc:oracle:thin:@localhost:1521:xe");
        jTextFieldRelationalUrl.setMinimumSize(new java.awt.Dimension(150, 20));
        jTextFieldRelationalUrl.setPreferredSize(new java.awt.Dimension(150, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 16, 0, 10);
        jPanelRelationalDatabases.add(jTextFieldRelationalUrl, gridBagConstraints);

        jTextFieldRelationalUsername.setMinimumSize(new java.awt.Dimension(150, 20));
        jTextFieldRelationalUsername.setPreferredSize(new java.awt.Dimension(150, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 16, 0, 10);
        jPanelRelationalDatabases.add(jTextFieldRelationalUsername, gridBagConstraints);

        jTextFieldRelationalPassword.setMinimumSize(new java.awt.Dimension(150, 20));
        jTextFieldRelationalPassword.setPreferredSize(new java.awt.Dimension(150, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 16, 0, 10);
        jPanelRelationalDatabases.add(jTextFieldRelationalPassword, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 40.0;
        add(jPanelRelationalDatabases, gridBagConstraints);

        jPanelMigrations.setLayout(new java.awt.GridBagLayout());

        jButtonRelationalToObjectMigration.setText("->");
        jButtonRelationalToObjectMigration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRelationalToObjectMigrationActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanelMigrations.add(jButtonRelationalToObjectMigration, gridBagConstraints);

        jButtonObjectToRelationalMigration.setText("<-");
        jButtonObjectToRelationalMigration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonObjectToRelationalMigrationActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanelMigrations.add(jButtonObjectToRelationalMigration, gridBagConstraints);

        jLabelMigrations.setText(I18n.getString("migration"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanelMigrations.add(jLabelMigrations, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weightx = 20.0;
        add(jPanelMigrations, gridBagConstraints);

        jPanelObjectDatabases.setLayout(new java.awt.GridBagLayout());

        jPanelORMappingInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(I18n.getString("fillonlyforormigration")));
        jPanelORMappingInfo.setLayout(new java.awt.GridBagLayout());

        jLabelJarFile.setText(I18n.getString("compiledcodepath"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        jPanelORMappingInfo.add(jLabelJarFile, gridBagConstraints);

        jButtonJarBrowse.setText(I18n.getString("browse"));
        jButtonJarBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonJarBrowseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 5);
        jPanelORMappingInfo.add(jButtonJarBrowse, gridBagConstraints);

        jTextFieldObjectCompiledFolder.setMinimumSize(new java.awt.Dimension(150, 20));
        jTextFieldObjectCompiledFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldObjectCompiledFolderActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(7, 2, 0, 0);
        jPanelORMappingInfo.add(jTextFieldObjectCompiledFolder, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 100.0;
        jPanelObjectDatabases.add(jPanelORMappingInfo, gridBagConstraints);

        jLabelObjectedBatabase.setText(I18n.getString("objectdatabase"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 0);
        jPanelObjectDatabases.add(jLabelObjectedBatabase, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
        jPanelObjectDatabases.add(jSeparator3, gridBagConstraints);

        jLabelLocal.setText(I18n.getString("local"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 0);
        jPanelObjectDatabases.add(jLabelLocal, gridBagConstraints);

        jLabelFile.setText(I18n.getString("fileobectdatabase"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        jPanelObjectDatabases.add(jLabelFile, gridBagConstraints);

        jTextFieldObjectDatabaseFilename.setMinimumSize(new java.awt.Dimension(150, 20));
        jTextFieldObjectDatabaseFilename.setPreferredSize(new java.awt.Dimension(150, 20));
        jTextFieldObjectDatabaseFilename.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldObjectDatabaseFilenameActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.insets = new java.awt.Insets(7, 2, 0, 0);
        jPanelObjectDatabases.add(jTextFieldObjectDatabaseFilename, gridBagConstraints);

        jButtonBrowse.setText(I18n.getString("browse"));
        jButtonBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBrowseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 10);
        jPanelObjectDatabases.add(jButtonBrowse, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weightx = 40.0;
        add(jPanelObjectDatabases, gridBagConstraints);

        jProgressBar1.setMinimumSize(new java.awt.Dimension(150, 19));
        jProgressBar1.setPreferredSize(new java.awt.Dimension(150, 19));
        jProgressBar1.setVisible(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        add(jProgressBar1, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonRelationalToObjectMigrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRelationalToObjectMigrationActionPerformed
        relationalToObjectMigration();
    }//GEN-LAST:event_jButtonRelationalToObjectMigrationActionPerformed

    private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBrowseActionPerformed

        String filename = jTextFieldObjectDatabaseFilename.getText();

        if(filename == null || filename.length() == 0) {
            filename = "."; //set to current directory
        }

        jFileChooserDb4oFilename.setSelectedFile(new File(filename));
        jFileChooserDb4oFilename.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jFileChooserDb4oFilename.setMultiSelectionEnabled(false);

        int result = jFileChooserDb4oFilename.showSaveDialog(this);

        if(result == JFileChooser.APPROVE_OPTION) {
            File selectedFile = jFileChooserDb4oFilename.getSelectedFile();

            if(selectedFile.exists()) {
                String message = I18n.getString("selectedfileexist");
                message = String.format(message, selectedFile.getAbsolutePath());

                int answer = JOptionPane.showOptionDialog(this, message,
                    I18n.getString("savewarnings"), JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, null, null);

                if(answer == JOptionPane.YES_OPTION) {
                    jTextFieldObjectDatabaseFilename.setText(
                        selectedFile.getAbsolutePath());
                }
            } else {
                jTextFieldObjectDatabaseFilename.setText(
                        selectedFile.getAbsolutePath());
            }
        }

    }//GEN-LAST:event_jButtonBrowseActionPerformed

    private void jButtonObjectToRelationalMigrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonObjectToRelationalMigrationActionPerformed
        objectToRelationalMigration();
    }//GEN-LAST:event_jButtonObjectToRelationalMigrationActionPerformed

    private void jTextFieldObjectCompiledFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldObjectCompiledFolderActionPerformed
        
    }//GEN-LAST:event_jTextFieldObjectCompiledFolderActionPerformed

    private void jTextFieldObjectDatabaseFilenameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldObjectDatabaseFilenameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldObjectDatabaseFilenameActionPerformed

    private void jButtonJarBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonJarBrowseActionPerformed
        // TODO add your handling code here:
        String filename = jTextFieldObjectCompiledFolder.getText();

        if(filename == null || filename.length() == 0) {
            filename = "."; //set to current directory
        }

        jFileChooserDb4oCodeFolder.setSelectedFile(new File(filename));
        jFileChooserDb4oCodeFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        jFileChooserDb4oCodeFolder.setMultiSelectionEnabled(false);

        int result = jFileChooserDb4oCodeFolder.showOpenDialog(this);

        if(result == JFileChooser.APPROVE_OPTION) {
            File selectedFile = jFileChooserDb4oCodeFolder.getSelectedFile();

            if(!selectedFile.exists()) {
                String message = I18n.getString("choosefoldernotexist");

                JOptionPane.showOptionDialog(this, message,
                    I18n.getString("choosefoldernotexist"), JOptionPane.OK_OPTION,
                    JOptionPane.ERROR_MESSAGE, null, null, null);

            } else {
                jTextFieldObjectCompiledFolder.setText(
                        selectedFile.getAbsolutePath());
            }
        }
    }//GEN-LAST:event_jButtonJarBrowseActionPerformed

    public void objectToRelationalMigration() {
        ConnectionValues connValues = new ConnectionValues();
        // gets inforamtion from Form
        //connValues.setRelationalDriver(jTextFieldRelationalDriver.getText());
        connValues.setRelationalURL(jTextFieldRelationalUrl.getText());
        connValues.setRelationalUsername(jTextFieldRelationalUsername.getText());
        connValues.setRelationalPassword(jTextFieldRelationalPassword.getText());
        connValues.setObjectFilename(jTextFieldObjectDatabaseFilename.getText());
        connValues.setObjectCompiledFolder(jTextFieldObjectCompiledFolder.getText());

        jTextAreaLog.setText("");

        try {
            dataWanderPresenter.object2RelationalMigration(connValues);
        } catch (ConnectionValuesException ex) {
            showErrorDialog(ex);
        }
    }

    public void relationalToObjectMigration() {
        ConnectionValues connValues = new ConnectionValues();
        // gets inforamtion from Form
        //connValues.setRelationalDriver(jTextFieldRelationalDriver.getText());
        connValues.setRelationalURL(jTextFieldRelationalUrl.getText());
        connValues.setRelationalUsername(jTextFieldRelationalUsername.getText());
        connValues.setRelationalPassword(jTextFieldRelationalPassword.getText());
        connValues.setObjectFilename(jTextFieldObjectDatabaseFilename.getText());

        jTextAreaLog.setText("");

        try {
            dataWanderPresenter.relational2ObjectMigration(connValues);
        } catch (ConnectionValuesException ex) {
            showErrorDialog(ex);
        }
    }

    public void enterLog(String message) {
        jTextAreaLog.append(message);
        jTextAreaLog.append("\n");
    }

    private String generateObjectDatabaseFilename() {
        String userDir = System.getProperty("user.dir");
        if(!userDir.endsWith(""+File.separatorChar)) {
            userDir = userDir + File.separatorChar;
        }

        return userDir+"base.yap";
    }

    /**
     * Set Controls enabled. Use this metod when migration process is ended.
     */
    public  void disableInputsControls() {
        jProgressBar1.setVisible(true);
        jTextFieldObjectDatabaseFilename.setEnabled(false);
        jTextFieldRelationalPassword.setEnabled(false);
        jTextFieldRelationalUrl.setEnabled(false);
        jTextFieldRelationalUsername.setEnabled(false);
        jButtonRelationalToObjectMigration.setEnabled(false);
        jTextFieldObjectCompiledFolder.setEnabled(false);
        jButtonBrowse.setEnabled(false);
        jButtonJarBrowse.setEnabled(false);
        jButtonObjectToRelationalMigration.setEnabled(false);
    }

    /**
     * Disable imputs controls. Use this metod when migration proces is in
     * progress.
     */
    public void enableInputsControls() {
        jProgressBar1.setVisible(false);
        jProgressBar1.setValue(0);
        jTextFieldObjectDatabaseFilename.setEnabled(true);
        jTextFieldRelationalPassword.setEnabled(true);
        jTextFieldRelationalUrl.setEnabled(true);
        jTextFieldRelationalUsername.setEnabled(true);
        jButtonRelationalToObjectMigration.setEnabled(true);
        jTextFieldObjectCompiledFolder.setEnabled(true);
        jButtonBrowse.setEnabled(true);
        jButtonJarBrowse.setEnabled(true);
        jButtonObjectToRelationalMigration.setEnabled(true);
    }
    
    /**
     * To show progress of migration. This method gives arguments form 0 to 100
     * @param procente
     */
    public void showMigrationProgress(int procente) {
        jProgressBar1.setValue(procente);
    }

    private void showErrorDialog(ConnectionValuesException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(),
                I18n.getString("errortitle"),
                JOptionPane.ERROR_MESSAGE | JOptionPane.OK_OPTION);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonBrowse;
    private javax.swing.JButton jButtonJarBrowse;
    private javax.swing.JButton jButtonObjectToRelationalMigration;
    private javax.swing.JButton jButtonRelationalToObjectMigration;
    private javax.swing.JFileChooser jFileChooserDb4oCodeFolder;
    private javax.swing.JFileChooser jFileChooserDb4oFilename;
    private javax.swing.JLabel jLabelFile;
    private javax.swing.JLabel jLabelJarFile;
    private javax.swing.JLabel jLabelLocal;
    private javax.swing.JLabel jLabelLog;
    private javax.swing.JLabel jLabelMigrations;
    private javax.swing.JLabel jLabelObjectedBatabase;
    private javax.swing.JLabel jLabelPassword;
    private javax.swing.JLabel jLabelRelationalDatabase;
    private javax.swing.JLabel jLabelURL;
    private javax.swing.JLabel jLabelUsername;
    private javax.swing.JPanel jPanelMigrations;
    private javax.swing.JPanel jPanelORMappingInfo;
    private javax.swing.JPanel jPanelObjectDatabases;
    private javax.swing.JPanel jPanelRelationalDatabases;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextArea jTextAreaLog;
    private javax.swing.JTextField jTextFieldObjectCompiledFolder;
    private javax.swing.JTextField jTextFieldObjectDatabaseFilename;
    private javax.swing.JTextField jTextFieldRelationalPassword;
    private javax.swing.JTextField jTextFieldRelationalUrl;
    private javax.swing.JTextField jTextFieldRelationalUsername;
    // End of variables declaration//GEN-END:variables

}
